#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int digitsum(int n)
    {
        int sum = 0;
        while (n)
        {
            int digit = n % 10;
            //cout<<"digit:"<<digit<<endl;
            sum += (digit * digit);
            n /= 10;
        }
        //cout<<"sum:"<<sum<<endl;
        return sum;
    }
    bool isHappy(int n) {
        int left = digitsum(n);
        int right = digitsum(left);
        while (left != right)
        {
            left = digitsum(left);
            right = digitsum(digitsum(right));
        }
        if (left == 1)
            return true;
        else
            return false;
    }
};